﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class LoginForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {

            var username = Login1.UserName;
            var password = Login1.Password;

            var sqlOther = string.Format("select * from Users where username='{0}' and password='{1}'", username, password);
            var dtOther = DbHelper.GetDataTable(sqlOther);
            if (dtOther.Rows.Count == 1)
            {
                var item = dtOther.Rows[0];
                var isActived = (bool)item.ItemArray[3];
                var isDelted = (bool)item.ItemArray[4];
                var Password = item.ItemArray[2].ToString();
                if (isDelted)
                {
                    Label1.Text = "该用户已被删除";

                }
                else
                {
                    if (isActived)
                    {
                        if (password == Password)
                        {
                            Response.Redirect("Default.aspx");
                        }
                        else
                        {
                            Label1.Text = "用户名或密码错误";
                        }
                    }
                    else
                    {
                        Label1.Text = "该用户已被冻结";
                    }
                }
            }
            else
            {
                Label1.Text = "用户名或密码错误";
            }
        }
    }
}